package com.culture.bootdemo.controller.queue;

import com.culture.bootdemo.po.Answer;

import java.util.PriorityQueue;
import java.util.Queue;

/**
 * @author: wen
 * @date: 2023/7/26 16:01
 * PriorityQueue:  优先队列
 */
public class PriorityQueueDemo {


    public static void main(String[] args) {
        Queue<Answer> res = new PriorityQueue<>((o1, o2) -> {
            //按照commentId由低到高入队列以及出队列
            Integer commentId1 = o1.getCommentId();
            Integer commentId2 = o2.getCommentId();
            return commentId1 - commentId2;
        });

        res.add(new Answer(1, 1));
        res.add(new Answer(2, 5));
        res.add(new Answer(3, 2));
        res.add(new Answer(4, 4));
        res.add(new Answer(5, 7));

        while (!res.isEmpty()) {
            System.out.println(res.poll().toString());
        }
    }
}
